#include "mapwidget.h"

#include <QQmlEngine>
#include <QVariant>
#include <QQmlContext>
#include <QDebug>

MapWidget::MapWidget(QWidget *parent) : QWidget(parent)
{
    m_mapView=new QQuickView();
    m_layout=new QVBoxLayout(this);
    setupWidget();
}

void MapWidget::updateMap()
{
    m_mapView->setSource(QUrl());
    QUrl source("qrc:/qml/map.qml");
    m_mapView->setSource(source);
}

void MapWidget::setupWidget()
{
    m_mapView->setResizeMode(QQuickView::SizeRootObjectToView);
    //注册mapValue对象到qml中
    qmlRegisterType<MapValue>();
    m_mapView->engine()->rootContext()->setContextProperty("mapValue",&m_value);
    QUrl source("qrc:/qml/map.qml");
    m_mapView->setSource(source);
    m_viewContainer = QWidget::createWindowContainer(m_mapView);
    m_layout->addWidget(m_viewContainer);
    m_viewContainer->setMinimumSize(m_mapView->size());
}
